package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.makeramen.roundedimageview.RoundedImageView;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.packers.EngineeringCompanyEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
*@author liwei
*@date 2021/3/24
*description:
*/
public class EngineeringCompanyAdapter extends BaseRecycleAdapter<EngineeringCompanyEntity> {

    private RequestManager requestManager;

    public EngineeringCompanyAdapter(Context context, List<EngineeringCompanyEntity> data, RequestManager requestManager) {
        super(context, R.layout.item_packer_engineering_company, data);
        this.requestManager = requestManager;
    }

    @Override
    public void convert(ItemViewHolder holder, final EngineeringCompanyEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        RoundedImageView ivPackerAvatar = holder.itemView.findViewById(R.id.iv_packer_avatar);
        if (null != entity.getCompanyIcon() && !TextUtils.isEmpty(entity.getCompanyIcon())) {
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.gongsiqiye)
                    .transforms(new CenterCrop(), new RoundedCorners(8));
            requestManager.load(entity.getCompanyIcon()).apply(options).into(ivPackerAvatar);
        } else {
            requestManager.load(R.mipmap.gongsiqiye).into(ivPackerAvatar);
        }
        TextView tvAuthTime = holder.itemView.findViewById(R.id.tv_auth_time);
        tvAuthTime.setText(String.format("%s", DateUtils.timestampToDate(entity.getAuthTime())));

        ///临时保持和IOS数据显示一致，可修改
        TextView teamType = holder.itemView.findViewById(R.id.teamType);
        if (TextUtils.isEmpty(entity.getTeamType())) {
            teamType.setText("工程公司");
        } else {
            teamType.setText(entity.getTeamType());
        }
    }
}